package com.sundablog.controller.systemsetup.basicsetup.shortmessage;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sundablog.pojo.ShortMessage;
import com.sundablog.result.BaseResult;
import com.sundablog.service.systemsetup.basicsetup.shortmessage.ShortMessageService;

/**
 * 短信接口Controller类
 * @ClassName:  ShortMessageController   
 * @Description:TODO(这里用一句话描述这个类的作用)   
 * @author: 哒哒 
 * @date:   2018年1月2日 下午6:55:18   
 *     
 * @Copyright: 2018 www.sundablog.com Inc. All rights reserved.
 */
@RequestMapping("/systemsetup/basicsetup/shortmessage")
@Controller
public class ShortMessageController {

	@Autowired
	private ShortMessageService shortMessageService;
	
	/**
	 * 短信接口显示
	 * @Title: showIndex   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @return      
	 * @return: String      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_basicsetup_shortmessage_index")
	@RequestMapping("/index")
	public String showIndex() {
		return "systemsetup/basicsetup/shortmessage/index";
	}
	
	/**
	 * 获取短信接口配置
	 * @Title: getShortMessage   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_basicsetup_shortmessage_getShortMessage")
	@RequestMapping("/getShortMessage")
	@ResponseBody
	public BaseResult getShortMessage() {
		ShortMessage message = shortMessageService.getShortMessage();
		return BaseResult.build(200, "", message);
	}
	
	/**
	 * 更新短信接口设置
	 * @Title: updataShortMessage   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param shortMessage
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_basicsetup_shortmessage_updataShortMessage")
	@RequestMapping("/updataShortMessage")
	@ResponseBody
	public BaseResult updataShortMessage(ShortMessage shortMessage) {
		int i = shortMessageService.updataShortMessage(shortMessage);
		if (i > 0) {
			return BaseResult.build(200, BaseResult.updataSuccess);
		} else {
			return BaseResult.build(201, BaseResult.updataFail);
		}
	}
	/**
	 * 发送短信接口设置
	 * @Title: sendShortMessage   
	 * @Description: TODO(这里用一句话描述这个方法的作用)   
	 * @param: @param phone
	 * @param: @param content
	 * @param: @return      
	 * @return: BaseResult      
	 * @throws
	 */
	@RequiresPermissions("systemsetup_basicsetup_shortmessage_sendShortMessage")
	@RequestMapping("/sendShortMessage")
	@ResponseBody
	public BaseResult sendShortMessage(String phone, String content) {
		int i = shortMessageService.sendShortMessage(phone, content);
		if (i > 0) {
			return BaseResult.build(200, BaseResult.sendSuccess);
		} else {
			return BaseResult.build(201, BaseResult.sendFail);
		}	
	}	
}
